home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / diff.zip / DIFF.C < prev    next >
Text File  |  1994-07-16  |  20KB  |  724 lines

  1. /* GNU DIFF main routine.
  2.    Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU DIFF.
  5.  
  6. GNU DIFF is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU DIFF is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU DIFF; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* GNU DIFF was written by Mike Haertel, David Hayes,
  21.    Richard Stallman and Len Tower.  */
  22.  
  23. /* MS-DOS port (c) 1990 by Thorsten Ohl, ohl@gnu.ai.mit.edu
  24. This port is also distributed under the terms of the GNU General
  25. Public License as published by the Free Software Foundation.
  26.  
  27. Please note that this file is not identical to the original GNU release,
  28. you should have received this code as patch to the official release.
  29.  
  30.     Friday, 15 July 1994  Troy Rollo (troy@cbme.unsw.EDU.AU)
  31.  
  32.         - removed redundant declarations forr getopt()
  33. $Header: e:/gnu/diff/RCS/diff.c 1.15.0.2 91/03/12 17:06:09 tho Exp $  */
  34.  
  35. #define GDIFF_MAIN
  36. #include "regex.h"
  37. #include "diff.h"
  38. #include "getopt.h"
  39.  
  40. #ifdef __STDC__
  41. extern  void main (int argc, char **argv);
  42. static    void usage(void);
  43. static    char *option_list(char * *, int);
  44. static    void specify_style(enum output_style);
  45. static  int compare_files(char *, char *, char *, char *, int);
  46. #else
  47. static    void usage();
  48. static    char *option_list();
  49. static    void specify_style();
  50. static  int compare_files();
  51. #endif /* __STDC__ */
  52.  
  53. /* Nonzero for -r: if comparing two directories,
  54.    compare their common subdirectories recursively.  */
  55.  
  56. int recursive;
  57.  
  58. /* For debugging: don't do discard_confusing_lines.  */
  59.  
  60. int no_discards;
  61.  
  62. /* Return a string containing the command options with which diff was invoked.
  63.    Spaces appear between what were separate ARGV-elements.
  64.    There is a space at the beginning but none at the end.
  65.    If there were no options, the result is an empty string.
  66.  
  67.    Arguments: OPTIONVEC, a vector containing separate ARGV-elements, and COUNT,
  68.    the length of that vector.  */
  69.  
  70. static char *
  71. option_list (optionvec, count)
  72.      char **optionvec;  /* Was `vector', but that collides on Alliant.  */
  73.      int count;
  74. {
  75.   int i;
  76.   int length = 0;
  77.   char *result;
  78.  
  79.   for (i = 0; i < count; i++)
  80.     length += strlen (optionvec[i]) + 1;
  81.  
  82.   result = (char *) xmalloc (length + 1);
  83.   result[0] = 0;
  84.  
  85.   for (i = 0; i < count; i++)
  86.     {
  87.       strcat (result, " ");
  88.       strcat (result, optionvec[i]);
  89.     }
  90.  
  91.   return result;
  92. }
  93.  
  94. /* The numbers 129 and 130 that appear in the fourth element
  95.    for the context and unidiff entries are used as a way of
  96.    telling the big switch in `main' how to process those options.  */
  97.  
  98. static struct option longopts[] =
  99. {
  100.   {"ignore-blank-lines", 0, 0, 'B'},
  101.   {"context", 2, 0, 129},
  102.   {"ifdef", 1, 0, 'D'},
  103.   {"show-function-line", 1, 0, 'F'},
  104.   {"speed-large-files", 0, 0, 'H'},
  105.   {"ignore-matching-lines", 1, 0, 'I'},
  106.   {"file-label", 1, 0, 'L'},
  107.   {"entire-new-files", 0, 0, 'N'},
  108.   {"new-files", 0, 0, 'N'},
  109.   {"starting-file", 1, 0, 'S'},
  110.   {"initial-tab", 0, 0, 'T'},
  111.   {"text", 0, 0, 'a'},
  112.   {"all-text", 0, 0, 'a'},
  113.   {"ascii", 0, 0, 'a'},
  114.   {"ignore-space-change", 0, 0, 'b'},
  115.   {"minimal", 0, 0, 'd'},
  116.   {"ed", 0, 0, 'e'},
  117.   {"reversed-ed", 0, 0, 'f'},
  118.   {"ignore-case", 0, 0, 'i'},
  119.   {"print", 0, 0, 'l'},
  120.   {"rcs", 0, 0, 'n'},
  121.   {"show-c-function", 0, 0, 'p'},
  122.   {"binary", 0, 0, 'q'},
  123.   {"brief", 0, 0, 'q'},
  124.   {"recursive", 0, 0, 'r'},
  125.   {"report-identical-files", 0, 0, 's'},
  126.   {"expand-tabs", 0, 0, 't'},
  127.   {"ignore-all-space", 0, 0, 'w'},
  128.   {"unified", 2, 0, 130},
  129.   {"version", 0, 0, 'v'},
  130.   {0, 0, 0, 0}
  131. };
  132.  
  133. #ifdef __STDC__
  134. void
  135. #endif /* __STDC__ */
  136. main (argc, argv)
  137.      int argc;
  138.      char *argv[];
  139. {
  140.   int val;
  141.   int c;
  142.   int prev = -1;
  143.   int longind;
  144.   extern char *version_string;
  145.  
  146.   program = argv[0];
  147.  
  148.   /* Do our initializations. */
  149.   output_style = OUTPUT_NORMAL;
  150.   always_text_flag = FALSE;
  151.   ignore_space_change_flag = FALSE;
  152.   ignore_all_space_flag = FALSE;
  153.   length_varies = FALSE;
  154.   ignore_case_flag = FALSE;
  155.   ignore_blank_lines_flag = FALSE;
  156.   ignore_regexp = 0;
  157.   function_regexp = 0;
  158.   print_file_same_flag = FALSE;
  159.   entire_new_file_flag = FALSE;
  160.   no_details_flag = FALSE;
  161.   context = -1;
  162.   line_end_char = '\n';
  163.   tab_align_flag = FALSE;
  164.   tab_expand_flag = FALSE;
  165.   recursive = FALSE;
  166.   paginate_flag = FALSE;
  167.   ifdef_string = NULL;
  168.   heuristic = FALSE;
  169.   dir_start_file = NULL;
  170.   msg_chain = NULL;
  171.   msg_chain_end = NULL;
  172.   no_discards = 0;
  173.  
  174.   /* Decode the options.  */
  175.  
  176.   while ((c = getopt_long (argc, argv,
  177.                "0123456789abBcC:dD:efF:hHiI:lL:nNpqrsS:tTuvw",
  178.                longopts, &longind)) != EOF)
  179.     {
  180.       if (c == 0)        /* Long option. */
  181.     c = longopts[longind].val;
  182.       switch (c)
  183.     {
  184.       /* All digits combine in decimal to specify the context-size.  */
  185.     case '1':
  186.     case '2':
  187.     case '3':
  188.     case '4':
  189.     case '5':
  190.     case '6':
  191.     case '7':
  192.     case '8':
  193.     case '9':
  194.     case '0':
  195.       if (context == -1)
  196.         context = 0;
  197.       /* If a context length has already been specified,
  198.          more digits allowed only if they follow right after the others.
  199.          Reject two separate runs of digits, or digits after -C.  */
  200.       else if (prev < '0' || prev > '9')
  201.         fatal ("context length specified twice");
  202.  
  203.       context = context * 10 + c - '0';
  204.       break;
  205.  
  206.     case 'a':
  207.       /* Treat all files as text files; never treat as binary.  */
  208.       always_text_flag = 1;
  209.       break;
  210.  
  211.     case 'b':
  212.       /* Ignore changes in amount of whitespace.  */
  213.       ignore_space_change_flag = 1;
  214.       length_varies = 1;
  215.       break;
  216.  
  217.     case 'B':
  218.       /* Ignore changes affecting only blank lines.  */
  219.       ignore_blank_lines_flag = 1;
  220.       break;
  221.  
  222.     case 'C':
  223.     case 129:        /* +context[=lines] */
  224.     case 130:        /* +unified[=lines] */
  225.       if (optarg)
  226.         {
  227.           if (context >= 0)
  228.         fatal ("context length specified twice");
  229.           {
  230.         char *p;
  231.         for (p = optarg; *p; p++)
  232.           if (*p < '0' || *p > '9')
  233.             fatal ("invalid context length argument");
  234.           }
  235.           context = atoi (optarg);
  236.         }
  237.  
  238.       /* Falls through.  */
  239.     case 'c':
  240.       /* Make context-style output.  */
  241.       specify_style (c == 130 ? OUTPUT_UNIFIED : OUTPUT_CONTEXT);
  242.       break;
  243.  
  244.     case 'd':
  245.       /* Don't discard lines.  This makes things slower (sometimes much
  246.          slower) but will find a guaranteed minimal set of changes.  */
  247.       no_discards = 1;
  248.       break;
  249.  
  250.     case 'D':
  251.       /* Make merged #ifdef output.  */
  252.       specify_style (OUTPUT_IFDEF);
  253.       ifdef_string = optarg;
  254.       break;
  255.  
  256.     case 'e':
  257.       /* Make output that is a valid `ed' script.  */
  258.       specify_style (OUTPUT_ED);
  259.       break;
  260.  
  261.     case 'f':
  262.       /* Make output that looks vaguely like an `ed' script
  263.          but has changes in the order they appear in the file.  */
  264.       specify_style (OUTPUT_FORWARD_ED);
  265.       break;
  266.  
  267.     case 'F':
  268.       /* Show, for each set of changes, the previous line that
  269.          matches the specified regexp.  Currently affects only
  270.          context-style output.  */
  271.       function_regexp = optarg;
  272.       break;
  273.  
  274.     case 'h':
  275.       /* Split the files into chunks of around 1500 lines
  276.          for faster processing.  Usually does not change the result.
  277.  
  278.          This currently has no effect.  */
  279.       break;
  280.  
  281.     case 'H':
  282.       /* Turn on heuristics that speed processing of large files
  283.          with a small density of changes.  */
  284.       heuristic = 1;
  285.       break;
  286.  
  287.     case 'i':
  288.       /* Ignore changes in case.  */
  289.       ignore_case_flag = 1;
  290.       break;
  291.  
  292.     case 'I':
  293.       /* Ignore changes affecting only lines that match the
  294.          specified regexp.  */
  295.       ignore_regexp = optarg;
  296.       break;
  297.  
  298.     case 'l':
  299.       /* Pass the output through `pr' to paginate it.  */
  300.       paginate_flag = 1;
  301.       break;
  302.  
  303.     case 'L':
  304.       /* Specify file labels for `-c' output headers.  */
  305.       if (!file_label[0])
  306.         file_label[0] = optarg;
  307.       else if (!file_label[1])
  308.         file_label[1] = optarg;
  309.       else
  310.         fatal ("too many file label options");
  311.       break;
  312.  
  313.     case 'n':
  314.       /* Output RCS-style diffs, like `-f' except that each command
  315.          specifies the number of lines affected.  */
  316.       specify_style (OUTPUT_RCS);
  317.       break;
  318.  
  319.     case 'N':
  320.       /* When comparing directories, if a file appears only in one
  321.          directory, treat it as present but empty in the other.  */
  322.       entire_new_file_flag = 1;
  323.       break;
  324.  
  325.     case 'p':
  326.       /* Make context-style output and show name of last C function.  */
  327.       specify_style (OUTPUT_CONTEXT);
  328.       function_regexp = "^[_a-zA-Z]";
  329.       break;
  330.  
  331.     case 'q':
  332.       no_details_flag = 1;
  333.       break;
  334.  
  335.     case 'r':
  336.       /* When comparing directories, 
  337.          recursively compare any subdirectories found.  */
  338.       recursive = 1;
  339.       break;
  340.  
  341.     case 's':
  342.       /* Print a message if the files are the same.  */
  343.       print_file_same_flag = 1;
  344.       break;
  345.  
  346.     case 'S':
  347.       /* When comparing directories, start with the specified
  348.          file name.  This is used for resuming an aborted comparison.  */
  349.       dir_start_file = optarg;
  350.       break;
  351.  
  352.     case 't':
  353.       /* Expand tabs to spaces in the output so that it preserves
  354.          the alignment of the input files.  */
  355.       tab_expand_flag = 1;
  356.       break;
  357.  
  358.     case 'T':
  359.       /* Use a tab in the output, rather than a space, before the
  360.          text of an input line, so as to keep the proper alignment
  361.          in the input line without changing the characters in it.  */
  362.       tab_align_flag = 1;
  363.       break;
  364.  
  365.     case 'v':
  366.       printf ("GNU diff version %s\n", version_string);
  367.       break;
  368.  
  369.     case 'u':
  370.       /* Output the context diff in unidiff format.  */
  371.       specify_style (OUTPUT_UNIFIED);
  372.       break;
  373.  
  374.     case 'w':
  375.       /* Ignore horizontal whitespace when comparing lines.  */
  376.       ignore_all_space_flag = 1;
  377.       length_varies = 1;
  378.       break;
  379.  
  380.     default:
  381.       usage ();
  382.     }
  383.       prev = c;
  384.     }
  385.  
  386.   if (optind != argc - 2)
  387.     usage ();
  388.  
  389.   if (ignore_regexp)
  390.     {
  391.       char *val;
  392.       bzero (&ignore_regexp_compiled, sizeof ignore_regexp_compiled);
  393.       val = re_compile_pattern (ignore_regexp, strlen (ignore_regexp),
  394.                 &ignore_regexp_compiled);
  395.       if (val != 0)
  396.     error ("%s: %s", ignore_regexp, val);
  397.       ignore_regexp_compiled.fastmap = (char *) xmalloc (256);
  398.     }
  399.  
  400.   if (function_regexp)
  401.     {
  402.       char *val;
  403.       bzero (&function_regexp_compiled, sizeof function_regexp_compiled);
  404.       val = re_compile_pattern (function_regexp, strlen (function_regexp),
  405.                 &function_regexp_compiled);
  406.       if (val != 0)
  407.     error ("%s: %s", function_regexp, val);
  408.       function_regexp_compiled.fastmap = (char *) xmalloc (256);
  409.     }
  410.  
  411.   if (output_style != OUTPUT_CONTEXT && output_style != OUTPUT_UNIFIED)
  412.     context = 0;
  413.   else if (context == -1)
  414.     /* Default amount of context for -c.  */
  415.     context = 3;
  416.  
  417.   switch_string = option_list (argv + 1, optind - 1);
  418.  
  419.   val = compare_files (0, argv[optind], 0, argv[optind + 1], 0);
  420.  
  421.   /* Print any messages that were saved up for last.  */
  422.   print_message_queue ();
  423.  
  424.   if (ferror (stdout) || fclose (stdout) != 0)
  425.     fatal ("write error");
  426.   exit (val);
  427. }
  428.  
  429. void
  430. usage ()
  431. {
  432.   fprintf (stderr, "\
  433. Usage: diff [-#] [-abBcdefhHilnNprstTuvw] [-C lines] [-F regexp] [-I regexp]\n\
  434.        [-L label [-L label]] [-S file] [-D symbol] [+ignore-blank-lines]\n\
  435.        [+context[=lines]] [+unified[=lines]] [+ifdef=symbol]\n\
  436.        [+show-function-line=regexp]\n");
  437.   fprintf (stderr, "\
  438.        [+speed-large-files] [+ignore-matching-lines=regexp] [+new-file]\n\
  439.        [+initial-tab] [+starting-file=file] [+text] [+all-text] [+ascii]\n\
  440.        [+minimal] [+ignore-space-change] [+ed] [+reversed-ed] [+ignore-case]\n");
  441.   fprintf (stderr, "\
  442.        [+print] [+rcs] [+show-c-function] [+binary] [+brief] [+recursive]\n\
  443.        [+report-identical-files] [+expand-tabs] [+ignore-all-space]\n\
  444.        [+file-label=label [+file-label=label]] [+version] path1 path2\n");
  445.   exit (2);
  446.  
  447. void
  448. specify_style (style)
  449.      enum output_style style;
  450. {
  451.   if (output_style != OUTPUT_NORMAL
  452.       && output_style != style)
  453.     error ("conflicting specifications of output style");
  454.   output_style = style;
  455. }
  456.  
  457. /* Compare two files (or dirs) with specified names
  458.    DIR0/NAME0 and DIR1/NAME1, at level DEPTH in directory recursion.
  459.    (if DIR0 is 0, then the name is just NAME0, etc.)
  460.    This is self-contained; it opens the files and closes them.
  461.  
  462.    Value is 0 if files are identical, 1 if different,
  463.    2 if there is a problem opening them.  */
  464.  
  465. int
  466. compare_files (dir0, name0, dir1, name1, depth)
  467.      char *dir0, *dir1;
  468.      char *name0, *name1;
  469.      int depth;
  470. {
  471.   static char Standard_Input[] = "Standard Input";
  472.   struct file_data inf[2];
  473.   register int i;
  474.   int val;
  475.   int errorcount = 0;
  476.   int stat_result[2];
  477.  
  478.   /* If this is directory comparison, perhaps we have a file
  479.      that exists only in one of the directories.
  480.      If so, just print a message to that effect.  */
  481.  
  482.   if (! entire_new_file_flag && (name0 == 0 || name1 == 0))
  483.     {
  484.       char *name = name0 == 0 ? name1 : name0;
  485.       char *dir = name0 == 0 ? dir1 : dir0;
  486.       message ("Only in %s: %s\n", dir, name);
  487.       /* Return 1 so that diff_dirs will return 1 ("some files differ").  */
  488.       return 1;
  489.     }
  490.  
  491.   /* Mark any nonexistent file with -1 in the desc field.  */
  492.   /* Mark unopened files (i.e. directories) with -2. */
  493.  
  494.   inf[0].desc = name0 == 0 ? -1 : -2;
  495.   inf[1].desc = name1 == 0 ? -1 : -2;
  496.  
  497.   /* Now record the full name of each file, including nonexistent ones.  */
  498.  
  499.   if (name0 == 0)
  500.     name0 = name1;
  501.   if (name1 == 0)
  502.     name1 = name0;
  503.  
  504.   inf[0].name = dir0 == 0 ? name0 : concat (dir0, "/", name0);
  505.   inf[1].name = dir1 == 0 ? name1 : concat (dir1, "/", name1);
  506.  
  507.   /* Stat the files.  Record whether they are directories.
  508.      Record in stat_result whether stat fails.  */
  509.  
  510.   for (i = 0; i <= 1; i++)
  511.     {
  512.       bzero (&inf[i].stat, sizeof(struct stat));
  513.       inf[i].dir_p = 0;
  514.       stat_result[i] = 0;
  515.  
  516.       if (inf[i].desc != -1)
  517.     {
  518.       char *filename = inf[i].name;
  519.  
  520.       stat_result[i] = 
  521.         strcmp (filename, "-")
  522.           ? stat (filename, &inf[i].stat)
  523.           : fstat (0, &inf[i].stat);
  524.           
  525.       if (stat_result[i] < 0)
  526.         {
  527.           perror_with_name (filename);
  528.           errorcount = 1;
  529.         }
  530.       else
  531.         inf[i].dir_p = 
  532.           S_IFDIR == (inf[i].stat.st_mode & S_IFMT)
  533.           && strcmp (filename, "-");
  534.     }
  535.     }
  536.  
  537.   /* See if the two named files are actually the same physical file.
  538.      If so, we know they are identical without actually reading them.  */
  539.  
  540. #ifndef MSDOS
  541.   if (output_style != OUTPUT_IFDEF
  542.       && inf[0].stat.st_ino == inf[1].stat.st_ino
  543.       && inf[0].stat.st_dev == inf[1].stat.st_dev
  544.       && stat_result[0] == 0
  545.       && stat_result[1] == 0)
  546.     {
  547.       val = 0;
  548.       goto done;
  549.     }
  550. #endif /* MSDOS */
  551.  
  552.   if (name0 == 0)
  553.     inf[0].dir_p = inf[1].dir_p;
  554.   if (name1 == 0)
  555.     inf[1].dir_p = inf[0].dir_p;
  556.  
  557.   /* Open the files and record their descriptors.  */
  558.  
  559.   for (i = 0; i <= 1; i++)
  560.     {
  561.       if (inf[i].desc == -1)
  562.     ;
  563.       else if (!strcmp (inf[i].name, "-"))
  564.     {
  565.       inf[i].desc = 0;
  566.       inf[i].name = Standard_Input;
  567.     }
  568.       /* Don't bother opening if stat already failed.  */
  569.       else if (stat_result[i] == 0 && ! inf[i].dir_p)
  570.     {
  571.       char *filename = inf[i].name;
  572.  
  573.       inf[i].desc = open (filename, O_RDONLY, 0);
  574.       if (0 > inf[i].desc)
  575.         {
  576.           perror_with_name (filename);
  577.           errorcount = 1;
  578.         }
  579.     }
  580.     }
  581.  
  582.   if (errorcount)
  583.     {
  584.  
  585.       /* If either file should exist but fails to be opened, return 2.  */
  586.  
  587.       val = 2;
  588.  
  589.     }
  590.   else if (inf[0].dir_p && inf[1].dir_p)
  591.     {
  592.       if (output_style == OUTPUT_IFDEF)
  593.     fatal ("-D option not supported with directories");
  594.  
  595.       /* If both are directories, compare the files in them.  */
  596.  
  597.       if (depth > 0 && !recursive)
  598.     {
  599.       /* But don't compare dir contents one level down
  600.          unless -r was specified.  */
  601.       message ("Common subdirectories: %s and %s\n",
  602.            inf[0].name, inf[1].name);
  603.       val = 0;
  604.     }
  605.       else
  606.     {
  607.       val = diff_dirs (inf[0].name, inf[1].name, 
  608.                compare_files, depth, 0, 0);
  609.     }
  610.  
  611.     }
  612.   else if (depth == 0 && (inf[0].dir_p || inf[1].dir_p))
  613.     {
  614.  
  615.       /* If only one is a directory, and it was specified in the command line,
  616.      use the file in that dir whose basename matches the other file.  */
  617.  
  618.       int dir_arg = (inf[0].dir_p ? 0 : 1);
  619.       int fnm_arg = (inf[0].dir_p ? 1 : 0);
  620.       char *p = rindex (inf[fnm_arg].name, '/');
  621.       char *filename = concat (inf[dir_arg].name,  "/",
  622.                    (p ? p+1 : inf[fnm_arg].name));
  623.  
  624.       if (inf[fnm_arg].name == Standard_Input)
  625.     fatal ("can't compare - to a directory");
  626.  
  627.       inf[dir_arg].desc = open (filename, O_RDONLY, 0);
  628.  
  629.       if (0 > inf[dir_arg].desc)
  630.     {
  631.       perror_with_name (filename);
  632.       val = 2;
  633.     }
  634.       else
  635.     {
  636.       /* JF: patch from the net to check and make sure we can really free
  637.          this.  If it's from argv[], freeing it is a *really* bad idea */
  638.       if (0 != (dir_arg ? dir1 : dir0))
  639.         free (inf[dir_arg].name);
  640.       inf[dir_arg].name = filename;
  641.       if (fstat (inf[dir_arg].desc, &inf[dir_arg].stat) < 0)
  642.         pfatal_with_name (inf[dir_arg].name);
  643.  
  644.       inf[dir_arg].dir_p
  645.         = (S_IFDIR == (inf[dir_arg].stat.st_mode & S_IFMT));
  646.       if (inf[dir_arg].dir_p)
  647.         {
  648.           error ("%s is a directory but %s is not",
  649.              inf[dir_arg].name, inf[fnm_arg].name);
  650.           val = 1;
  651.         }
  652.       else
  653.         val = diff_2_files (inf, depth);
  654.     }
  655.  
  656.     }
  657.   else if (depth > 0 && (inf[0].dir_p || inf[1].dir_p))
  658.     {
  659.       /* Perhaps we have a subdirectory that exists only in one directory.
  660.      If so, just print a message to that effect.  */
  661.  
  662.       if (inf[0].desc == -1 || inf[1].desc == -1)
  663.     {
  664.       if (entire_new_file_flag && recursive)
  665.         val = diff_dirs (inf[0].name, inf[1].name, compare_files, depth,
  666.                  inf[0].desc == -1, inf[1].desc == -1);
  667.       else
  668.         {
  669.           char *dir = (inf[0].desc == -1) ? dir1 : dir0;
  670.           message ("Only in %s: %s\n", dir, name0);
  671.           val = 1;
  672.         }
  673.     }
  674.       else
  675.     {
  676.       /* We have a subdirectory in one directory
  677.          and a file in the other.  */
  678.  
  679.       if (inf[0].dir_p)
  680.         message ("%s is a directory but %s is not\n",
  681.              inf[0].name, inf[1].name);
  682.       else
  683.         message ("%s is a directory but %s is not\n",
  684.              inf[1].name, inf[0].name);
  685.       /* This is a difference.  */
  686.       val = 1;
  687.     }
  688.     }
  689.   else
  690.     {
  691.  
  692.       /* Both exist and both are ordinary files.  */
  693.  
  694.       val = diff_2_files (inf, depth);
  695.  
  696.     }
  697.  
  698.   /* Now the comparison has been done, if no error prevented it,
  699.      and VAL is the value this function will return.  */
  700.  
  701.   if (inf[0].desc >= 0)
  702.     close (inf[0].desc);
  703.   if (inf[1].desc >= 0)
  704.     close (inf[1].desc);
  705.  
  706.  done:
  707.   if (val == 0 && !inf[0].dir_p)
  708.     {
  709.       if (print_file_same_flag)
  710.     message ("Files %s and %s are identical\n",
  711.          inf[0].name, inf[1].name);
  712.     }
  713.   else
  714.     fflush (stdout);
  715.  
  716.   if (dir0 != 0)
  717.     free (inf[0].name);
  718.   if (dir1 != 0)
  719.     free (inf[1].name);
  720.  
  721.   return val;
  722. }
  723.